function vote(id, positive, kind) {
	$("#id").attr('value', id);
	$("#positive").attr('value', positive);
	$("#kind").attr('value', kind);
	
	$("#voting_form").submit();
}

$(document).ready(function(){
	server = "http://127.0.0.1:8000";
	
	$("#create_timeline").click(function(){
		$(location).attr("href","new");		
	});

	$("div.display_timeline").click(function(){
		$(location).attr("href",$(this).attr("id"));
	});

	$("div.vote_timeline_resources").click(function(){
		window.location.href = server + "/timelines/" + timeline_id + "/vote";
	});
		
	$("#search_events").click(function() {
		
		if ($('#date').val() == "") {
			$('#date').focus();
			alert("Por favor, preencha o campo data.");
		} else {
			$('#search_form').submit();
		}
	});
	
	$("#view_timeline").click(function() {
		timeline_id = $("#timeline_id").attr("value");
		window.location.href = server + "/timelines/" + timeline_id;
	});
	
	$("#add_asset").click(function(){
		if ($("#id_link").attr("value") === "") {
			alert("Link não pode ser vazio.");
			$("#id_link").focus();
			return;
		}
		$("#asset_form").submit();
	});
	
	$("#display_resources").click(function(){
		$(this).hide();
		$(".assets_list").css("display","block");
	});
	
	$("#hide_resources").click(function() {
		$(".assets_list").hide();
		$("#display_resources").show();
	});
	
	$("#import_later").click(function() {
		timeline_id = $("#timeline_id").attr("value");
		window.location.href = server + "/timelines/" + timeline_id;
	});

	$("#select_timelines").click(function() {
		checked = 0;
		
		$("INPUT[type='checkbox']").each(function(index) {
			if ($(this).is(':checked')) {
				checked += 1;
			}
		});
		
		if (checked === 0) {
			alert('É preciso selecionar pelo menos uma timeline.');
			return;
		} else {
			$("#select_timelines_form").submit();	
		}
	});
	
	$('#checkAllAuto').click(function() {
		$("INPUT[type='checkbox']").attr('checked', $('#checkAllAuto').is(':checked'));    
    });
    
    $("#import_events").click(function() {
		checked = 0;
		
		$("INPUT[type='checkbox']").each(function(index) {
			if ($(this).is(':checked')) {
				checked += 1;
			}
		});
		
		if (checked === 0) {
			alert('É preciso selecionar pelo menos um evento.');
			return;
		} else {
			$("#import_events_form").submit();	
		}
	});

	$("#new_event").click(function() {
		$("#action").attr("value", "Add");
		$("#edit_event").submit();
	});	

});
